import logging

import pytest

from resource.pom.gallery import Gallery
from utils.manager import MatchRules


@pytest.fixture(scope='function', autouse=True)
def func_setup_teardown(device):
    logging.info('------用例前置：预置视频资源------')
    app = Gallery
    device.mediatool_delete_all()
    device.hdc_file_send(app.video1, app.videos_dir)
    device.mediatool_send(app.videos_dir)
    yield
    logging.info('------用例后置：删除预置资源------')
    device.mediatool_delete_all()


class Test:
    app = Gallery

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入视频，点击选择一个视频')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.refresh_layout()
        device.click_element(device.get_element_by_key('TabPhotos'))
        device.click_element(device.get_element_by_key('Gesture_1'))
        logging.info('预期结果1.可以正常进入到视频')
        device.refresh_layout()
        device.assert_key_exist('ActionBarButtonBack')
        device.assert_key_exist('PhotoBrowserDateTitle')
        device.assert_key_exist('PhotoBrowserTimeLocationTitle')
        device.assert_key_exist('DetailMenuPanel')
        device.assert_key_exist('browserFocus_file', MatchRules.Contain)
        device.assert_key_exist('VideoPlayButton')
        device.assert_key_exist('ToolBarButtonFavor')
        device.assert_text_exist('收藏')
        device.assert_key_exist('ToolBarButtonEdit')
        device.assert_text_exist('编辑')
        device.assert_key_exist('ToolBarButtonDelete')
        device.assert_text_exist('删除')
        device.assert_key_exist('ToolBarButtonMore')
        device.assert_text_exist('更多')

        detail_menu_panel = device.get_element_by_key('DetailMenuPanel')
        toolbar_btn_more = device.get_element_by_key('ToolBarButtonMore')
        logging.info('步骤2.点击更多')
        device.click_element(toolbar_btn_more)
        logging.info('预期结果2.正常弹出选项框')
        device.refresh_layout()
        device.assert_text_exist('添加到相册')
        device.assert_text_exist('重命名')
        # 再点一下退出更多
        device.click_element(toolbar_btn_more)

        logging.info('步骤3.点击详细信息')
        device.click_element(detail_menu_panel)
        device.refresh_layout()
        logging.info('预期结果3.正常弹出详细信息弹窗内展示为图片/视频的名称、时间、大小、分辨率、时长')
        device.assert_type_exist('Dialog')
        device.assert_text_exist('详细信息')
        device.assert_text_exist('名称')
        assert device.get_element_by_key('ValueOfDetailTitle').get('text'), '名称未显示'
        device.assert_text_exist('时间')
        assert device.get_element_by_key('ValueOfDetailTime').get('text'), '时间未显示'
        device.assert_text_exist('大小')
        assert device.get_element_by_key('ValueOfDetailSize').get('text'), '大小未显示'
        device.assert_text_exist('分辨率')
        assert device.get_element_by_key('ValueOfDetailResolution').get('text'), '分辨率未显示'
        device.assert_text_exist('时长')
        assert device.get_element_by_key('ValueOfDetailDuration').get('text'), '时长未显示'
        device.assert_text_exist('知道了')
